<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>mytestAdmin</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/config.js" type="application/javascript"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>
		<div class="x-body">
			<button class="layui-btn" onclick="fresh()"><i class="layui-icon">ဂ</i></button>
			<button class="layui-btn" onclick="add()"><i class="layui-icon">&#xe608;</i> 添加请求</button>
			<button class="layui-btn" onclick="addmodel()"><i class="layui-icon">&#xe608;</i> 添加模型</button>
			<table class="layui-hide" id="jobList" lay-filter="jobList"></table>
		</div>
		<script type="text/html" id="action">
			<div class="layui-btn-group">
				<a title="编辑" class="layui-btn layui-btn layui-btn-xs layui-btn-primary" lay-event="edit">
					<i class="layui-icon">&#xe642;</i>
				</a>
				<a title="删除" class="layui-btn layui-btn-xs layui-btn-primary" lay-event="del">
					<i class="layui-icon">&#xe640;</i>
				</a>
				<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="up" title="上移">
					<i class="layui-icon">&#xe619;</i>
				</a>
				<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="down" title="下移">
					<i class="layui-icon">&#xe61a;</i>
				</a>
			</div>
		</script>
		<script>
			var id;
			layui.use(['layer'], function() {
				var layer = layui.layer;
				var router = layui.router();
				id = router.search.id;
			});

			layui.use('table', function() {
				var table = layui.table;

				table.render({
					elem: '#jobList', headers: {token: username,projectid: projectid},
					url: base_url + '/testcase/getcasestep/' + id,
					cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
						,
					cols: [
						[{
							field: 'ID',
							title: 'ID',
							width: 80
						}, {
							field: 'functionname',
							title: '类型'
						}, {
							field: 'operatename',
							title: '内容'
						}, {
							field: 'updatetime',
							title: '更新时间'
						}, {
							fixed: 'right',
							title: '操作',
							toolbar: '#action',
							width: 190
						}]
					]
				});

				//监听行工具事件
				table.on('tool(jobList)', function(obj) {
					var data = obj.data;
					if(obj.event === 'del') {
						layer.confirm('确定要从此用例中删除该步骤吗？', function(index) {
							$.ajax({
								url: base_url + '/testcase/delteststep/' + data.ID,
								type: 'get',
								data: {},
								dataType: 'json',
								success: function(result) {
									console.log(result)
									if(result.code == '0') {
										location.reload();
									} else {
										layer.msg(result.msg);
									}
								}
							});
							layer.close(index);
						});
					} else if(obj.event === 'edit') {
						if(data.functionname == 'request') {
							var ss = parent.layer.open({
								type: 2,
								title: '请求步骤编辑：' + data.operatename,
								area: ['1000px', '400px'],
								maxmin: true,
								content: ['edittestcasestep.html#/id=' + data.ID, 'yes'],
								end: function() {
									location.reload();
								}
							});
						} else if(data.functionname == 'model') {
							var ss = parent.layer.open({
								type: 2,
								title: '模型（'+data.operatename+'）步骤编辑',
								area: ['1000px', '400px'],
								maxmin: true,
								content: ['modelstep.html#/id=' + data.operateid, 'yes']
							});
						}
					} else if(obj.event === 'up') {
						$.ajax({
							url: base_url + '/testcase/teststep/up/' + data.ID,
							type: 'get',
							data: {},
							dataType: 'json',
							success: function(result) {
								console.log(result)
								if(result.code == '0') {
									location.reload();
								} else {
									layer.msg(result.msg);
								}
							}
						});
					} else if(obj.event === 'down') {
						$.ajax({
							url: base_url + '/testcase/teststep/down/' + data.ID,
							type: 'get',
							data: {},
							dataType: 'json',
							success: function(result) {
								console.log(result)
								if(result.code == '0') {
									location.reload();
								} else {
									layer.msg(result.msg);
								}
							}
						});
					} else if(obj.event === 'up') {
						$.ajax({
							url: base_url + '/testcase/teststep/up/' + data.ID,
							type: 'get',
							data: {},
							dataType: 'json',
							success: function(result) {
								console.log(result)
								if(result.code == '0') {
									location.reload();
								} else {
									layer.msg(result.msg);
								}
							}
						});
					}
				});
			});
		</script>
		<script>
			function add() {
				var ss = parent.layer.open({
					type: 2,
					title: '用例步骤添加',
					area: ['1000px', '400px'],
					maxmin: true,
					content: ['addtestcasestep.html#/id=' + id, 'yes'],
					end: function() {
						location.reload();
					}
				});
			}

			function addheader() {
				var ss = parent.layer.open({
					type: 2,
					title: 'Header头信息添加',
					area: ['1000px', '400px'],
					maxmin: true,
					content: ['addheader.html#/id=' + id, 'yes'],
					end: function() {
						location.reload();
					}
				});
			}

			function addmodel() {
				var ss = parent.layer.open({
					type: 2,
					title: '添加模型到用例步骤',
					area: ['1000px', '400px'],
					maxmin: true,
					content: ['addmodelforcase.html#/caseid=' + id, 'yes'],
					end: function() {
						location.reload();
					}
				});
			}
		</script>
	</body>

</html>